package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.controller.es.EsUnService;
import com.ruoyi.system.controller.es.dto.EsSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FyResourcesMapper;
import com.ruoyi.system.domain.FyResources;
import com.ruoyi.system.service.IFyResourcesService;

/**
 * 扩展资源Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Service
public class FyResourcesServiceImpl implements IFyResourcesService
{
    @Autowired
    private FyResourcesMapper fyResourcesMapper;
    @Autowired
    private EsUnService esUnService;
    /**
     * 查询扩展资源
     *
     * @param reId 扩展资源主键
     * @return 扩展资源
     */
    @Override
    public FyResources selectFyResourcesByReId(Long reId)
    {
        return fyResourcesMapper.selectFyResourcesByReId(reId);
    }

    /**
     * 查询扩展资源列表
     *
     * @param fyResources 扩展资源
     * @return 扩展资源
     */
    @Override
    public List<FyResources> selectFyResourcesList(FyResources fyResources)
    {
        return fyResourcesMapper.selectFyResourcesList(fyResources);
    }

    /**
     * 新增扩展资源
     *
     * @param fyResources 扩展资源
     * @return 结果
     */
    @Override
    public int insertFyResources(FyResources fyResources)
    {
        fyResources.setIsDelete(0l);

//        fyResources.setCreateTime(DateUtils.getNowDate());
        if (StringUtils.isEmpty(fyResources.getIsTop())){
            fyResources.setIsTop("N");
        }
        return fyResourcesMapper.insertFyResources(fyResources);
    }

    /**
     * 修改扩展资源
     *
     * @param fyResources 扩展资源
     * @return 结果
     */
    @Override
    public int updateFyResources(FyResources fyResources)
    {
        fyResources.setUpdateTime(DateUtils.getNowDate());
        return fyResourcesMapper.updateFyResources(fyResources);
    }

    /**
     * 批量删除扩展资源
     *
     * @param reIds 需要删除的扩展资源主键
     * @return 结果
     */
    @Override
    public int deleteFyResourcesByReIds(Long[] reIds)
    {
        for (Long l:reIds){
            FyResources fyResources=new FyResources();
            fyResources.setReId(l);
            fyResources.setIsDelete(1l);
            fyResourcesMapper.updateFyResources(fyResources);
            EsSearch esSearch=new EsSearch();
            esSearch.setId(fyResources.getReId());
            esSearch.setLanmu("资源-扩展资源");
            esSearch.setLanmuId(3);
            esUnService.delete(esSearch);
        }
        return 1;
    }

    /**
     * 删除扩展资源信息
     *
     * @param reId 扩展资源主键
     * @return 结果
     */
    @Override
    public int deleteFyResourcesByReId(Long reId)
    {
        return fyResourcesMapper.deleteFyResourcesByReId(reId);
    }
}
